package com.gxa.order.controller;

import com.gxa.common.commons.JsonResult;
import com.gxa.common.commons.R;
import com.gxa.common.utils.FileUtils;
import com.gxa.order.pojo.Hotel;
import com.gxa.order.service.HotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/Hotel")
public class HotelController {

    @Autowired
    private HotelService hotelService;

    /**
     *添加酒店和民宿
     * @param hotel json类型的酒店民宿实体类
     * @return
     */
    @PostMapping("/addHotel")
    public R addHotel(@RequestBody Hotel hotel){
        return hotelService.addHotel(hotel);
    }

    //根据条件查询所有的酒店民宿
    @PostMapping("/findAllHotelByCondition")
    public JsonResult findAllHotelByCondition(@RequestBody HashMap map){
        return hotelService.findAllHotelByCondition(map);
    }

    //根据id查找酒店和民宿
    @GetMapping("/findHotelById")
    public R findHotelById(Integer hotel_id){
        return hotelService.findHotelById(hotel_id);
    }

    /**
     * 根据酒店id编辑酒店和民宿
     * @param hotel
     * @return
     */
    @PostMapping("/updateHotelById")
    public R updateHotelById(@RequestBody Hotel hotel){
        return hotelService.updateHotelById(hotel);
    }

    /**
     * 下架上架酒店和民宿
     * @param hotel_id
     * @return
     */
    @GetMapping("/delHotelById")
    public R delHotelById(Integer hotel_id){
        return hotelService.delHotelById(hotel_id);
    }


    /**
     * 添加图片
     * @param file
     * @return
     */
    @PostMapping("/addImg")
    public R addImg(MultipartFile file, HttpServletRequest request){
        String s = FileUtils.fileUpload("/load", file, request);
        R r = new R();
        if (s!=null && s!=""){
            r.setCode(200);
            r.setMsg("文件上传成功");
            r.setData(s);
        }else {
            r.setCode(500);
            r.setMsg("文件上传出现故障");
        }
        return r;
    }


    /**
     * 审核通过
     * @param id
     * @return
     */
    @GetMapping("/agreeExamine")
    public R agreeExamine(Integer id){
        return hotelService.agreeExamine(id);
    }

    /**
     * 审核不通过
     * @param id
     * @return
     */
    @GetMapping("/notAgreeExamine")
    public R notAgreeExamine(Integer id){
        return hotelService.notAgreeExamine(id);
    }

    /**
     * 换房
     * @param map 需要住宿订单id，房间号
     * @return
     */
    @PostMapping("/exchangeRoom")
    public R exchangeRoom(@RequestBody HashMap map){
        return hotelService.exchangeRoom(map);
    }

    /**
     * 退房
     * @return
     */
    @PostMapping("/checkOut")
    public R checkOut(){
        return null;
    }

    /**
     * 添加房间数
     * @param hotel_id
     * @param room_number
     * @return
     */
    @GetMapping("/addRoomNumber")
    public R addRoomNumber(Integer hotel_id,Integer room_number){
        return hotelService.addRoomNumber(hotel_id,room_number);
    }
}
